package com.aifund.orderservice.reciver;

import com.aifund.common.dao.ExchangeDao;
import com.aifund.common.dao.ExchangeManTacticsDao;
import com.aifund.common.dao.FollowOrderCurrencyDao;
import com.aifund.common.dao.FollowOrderManTacticsDao;
import com.aifund.common.entity.AiExchange;
import com.aifund.common.entity.ExchangeManTactics;
import com.aifund.common.entity.FollowOrderCurrency;
import com.aifund.common.entity.FollowOrderManTactics;
import com.aifund.common.enums.DocumentaryInfo.FollowTypeEnum;
import com.aifund.common.enums.manTactics.TradeTypeEnum;
import com.aifund.common.enums.vertify.ExchangeManTacticsStatusEnum;
import com.aifund.common.mapper.ExchangeManTacticsMapper;
import com.aifund.orderservice.model.ClientOrderModel;
import com.aifund.orderservice.service.impl.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
@RabbitListener(queues = "client order")
public class MakeOrderReceiver {

    @Autowired
    FollowOrderCurrencyDao followOrderCurrencyDao;
    @Autowired
    ExchangeManTacticsMapper exchangeManTacticsMapper;
    @Autowired
    ExchangeDao exchangeDao;


    @RabbitHandler
    public void process(ClientOrderModel orderModel, Channel channel, Message message) throws IOException {

        String exchEn = orderModel.getExchange();
        AiExchange exch = exchangeDao.getByExchangeNameEn(exchEn);

        /**
         * 该交易api的所有策略
         */
        List<ExchangeManTactics> tacticsList = exchangeManTacticsMapper.getTacticsByCondition(exch.getId(), TradeTypeEnum.CONTRACT.getType(),orderModel.getUser_id(), ExchangeManTacticsStatusEnum.PASS_AUDIT.getStatus());
        for(ExchangeManTactics tactics : tacticsList){

            /**
             * 自动选择交易币种
             */
            if(tactics.isAutoSelectTransactionCurrency()){

            }
            /**
             * 查询是否满足策略币种要求
             */
            else{
                FollowOrderCurrency followOrderCurrency = followOrderCurrencyDao.getByFollowIdAndFollowTypeAndCurrency(tactics.getId(), FollowTypeEnum.EXCHANGE_MAN_FOLLOW.getType(), orderModel.getSymbol());
                if(followOrderCurrency != null){

                }
            }
        }
    }
}
